<?php
// +---------------------------------------------------------------------------+
// | This file is part of the KnowledgebasePublisher package                   |
// | KnowledgebasePublisher - web based knowledgebase publisher tool           |
// |                                                                           |
// | Author:  Evgeny Leontev <eleontev@gmail.com>                              |
// | Copyright (c) 2005 Evgeny Leontev                                         |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

class KBClientView_send extends KBClientView_common
{

	function &execute(&$manager) {
		
		$row = &$manager->getEntryById($this->entry_id, $this->category_id);
		$row = &$this->stripVars($row);
		if(!$row) { return; }
		
		$this->meta_title = $this->msg['send_link_msg'];
		$title = ''; //($this->controller->getSetting('show_title_nav')) ? $row['title'] : '';
		
		$data = $this->getTop($manager, $title, false);
		$data .= $this->getForm($manager, $title);
		$data .= $this->getEntry($manager, $row);
		
		return $data;		
	}
	
	
	function getEntry(&$manager, &$row)  {
		$tpl = &new tplTemplatez($this->template_dir . 'article.html');
		$tpl->tplParse(array_merge($row, $this->msg));
		return $tpl->tplPrint(1);
	}
	

	function getForm($manager, $entry_title) {
		$tpl = &new tplTemplatez($this->template_dir . 'send_form.html');
		
		$tpl->tplAssign('user_msg', $this->getErrors());
		$tpl->tplAssign('action_link', $this->_getLink('all'));
															  
		
		if($manager->is_registered && !$_POST) {
			$data = $this->stripVars($manager->getUserInfo($manager->user_id));
			$tpl->tplAssign('your_email', $data['email']);
			$tpl->tplAssign('name', $data['first_name'] . ' ' . $data['last_name']);
		}
		
		
		$link = $this->_getLink('entry', $this->category_id, $this->entry_id);
		
		// hidden	
		$tpl->tplAssign('entry_link', $link);
		$tpl->tplAssign('entry_title', $entry_title);
		
		$tpl->tplAssign('cancel_link', $link);
		$tpl->tplAssign($this->msg);
		$tpl->tplAssign($this->getFormData());
		
		$tpl->tplParse();
		return $tpl->tplPrint(1);
	}
	
	
	function validate($values) {
		
		require_once 'eleontev/Validator.php';
		
		$v =& new Validator($values, false);
		$v->required('required_msg', 'name');
		$v->regex('email_msg', 'email', 'your_email');
		$v->regex('email_msg', 'email', 'friend_email');
		
		return $v->getErrors();
	}
}
?>